package com.ansatsing.juc.executor.scenario0;

import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

public class Server {
    private ThreadPoolExecutor executor;
    public Server(){
        this.executor = (ThreadPoolExecutor) Executors.newCachedThreadPool();
    }
    public void executeTask(Task task){
        System.out.printf("Server: A new task has arrived\n");
        executor.execute(task);
        System.out.printf("Server: Pool Size: %d\n",executor.getPoolSize());
        System.out.printf("Server: Active Size: %d\n",executor.getActiveCount());
        System.out.printf("Server: Completed Size: %d\n",executor.getCompletedTaskCount());
    }
    public void endServer(){
        executor.shutdown();
        System.out.printf(">>>>>>Server: Pool Size: %d\n",executor.getPoolSize());
        System.out.printf(">>>>>>Server: Active Size: %d\n",executor.getActiveCount());
        System.out.printf(">>>>>>Server: Completed Size: %d\n",executor.getCompletedTaskCount());
    }
}
